<?php

namespace app\api\model;

use app\admin\controller\VipCard;
use app\admin\model\VipPrice;
use think\cache\driver\Redis;
use think\Model;
use think\model\concern\SoftDelete;

class VipModel extends ApiModel
{

    use SoftDelete;


    // 表名
    protected $name = 'vip';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    protected $deleteTime = 'delete_time';


    protected $vip_group = [1 => 'A类会员',2 => 'B类会员',3=>'C类会员'];

    protected $expire_time = 7*24*60*60;


    public function getVipList($prams)
    {
       $list = (new \app\admin\model\VipCard())
           ->where(['status' => 1])
           ->order('sort desc')
           ->field('id,name,vip_cate,price,desc')
           ->select()->toArray();
        // 分组数据
        $grouped = [];
        foreach ($list as $item) {
            $vipCate = $item['vip_cate'];
            $groupName = isset($this->vip_group[$vipCate]) ? $this->vip_group[$vipCate] : '未知类别';
            if (!isset($grouped[$groupName])) {
                $grouped[$groupName] = [];
            }
            $grouped[$groupName][] = $item;
        }
        return $this->api_success('获取成功',$grouped);
    }

    public function getVipReload($params = array()){
        $user = $params['uid'];
        $list = (new VipCardBill())->where(['member_id' => $user])->order('id desc')->paginate(10);
        foreach ($list as &$val){
            $val['create_time'] = date('Y-m-d H:i:s',$val['create_time']);
        }

        return $this->api_success('获取成功',$list);

    }


}
